package com.hoongs.v1.controller;

import com.hoongs.v1.entity.Comment;
import com.hoongs.v1.service.CommentService;
import com.hoongs.v1.utils.Result;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/comment")
public class CommentController {

    @Resource
    private CommentService commentService;

    @PostMapping("/save")
    @PreAuthorize("hasAnyAuthority('admin')")
    public Result save(Comment comment) {
        return commentService.save(comment);
    }

    @PostMapping("/add")
    @PreAuthorize("hasAnyAuthority('admin')")
    public Result add(Comment comment) {
        return commentService.add(comment);
    }

    @PostMapping("/remove")
    @PreAuthorize("hasAnyAuthority('admin')")
    public Result remove(String id) {
        return commentService.remove(id);
    }

    @PostMapping("/update")
    @PreAuthorize("hasAnyAuthority('admin')")
    public Result update(Comment comment) {
        return commentService.update(comment);
    }

    @GetMapping("/selectById")
    public Result selectById(String id) {
        return commentService.selectById(id);
    }

    @GetMapping("/selectList")
    public Result selectList(String article_id, String status) {
        return commentService.selectList(article_id, status);
    }

    @GetMapping("/selectPageList")
    public Result selectPageList(Integer page, Integer size) {
        return commentService.selectPageList(page, size);
    }

}
